import api from '@/libs/request'
import { FUNCTIONTYPE } from '@/store/modules/decoration'

/**
 * 保存装修控件和页面
 */
export const doSubmitControl = (data: any) => {
    return api.post('gruul-mall-shop/decoration/edit', data)
}
/**
 * 获取自定义页面列表
 */
export const doGetCustomPageList = (type: string) => {
    return api.get(`gruul-mall-shop/decoration/page/list?aggregationPlatform=${type}`)
}
/**
 * 根据id获取页面组件信息
 * @param {string} componentId
 */
export const doGetCustomPageComponent = (componentId: string) => {
    return api.get(`gruul-mall-shop/decoration/get?id=${componentId}`)
}
/**
 * 修改装修自定义页面名称
 * @param {string} name
 * @param {string} componentId
 */
export const doChangeCutomPageName = (name: string, componentId: string) => {
    return api.put(`gruul-mall-shop/decoration/page/update/${name}?id=${componentId}`)
}
/**
 * 设置装修自定义页面为首页展示
 */
export const doSetDefault = (componentId: string, platforms: string) => {
    return api.put(`gruul-mall-shop/decoration/set/home/page/${componentId}?aggregationPlatform=${platforms}`)
}

enum RETRIEVESORT {
    salePrice_desc,
    salePrice_asc,
    salesVolume_desc,
    salesVolume_asc,
    createTime_desc,
    createTime_asc,
    comprehensive_desc,
    comprehensive_asc,
}
export interface RetrieveParam {
    keyword: string
    categoryFirstId: string
    categorySecondId: string
    categoryThirdId: string
    platformCategoryFirstId: string
    platformCategorySecondId: string
    platformCategoryThirdId: string
    productId: string[] | string
    pageNum: number
    size: number
    sort: keyof typeof RETRIEVESORT | string
    minPrice: number | string
    maxPrice: number | string
    current: number
    pages: number
    shopId: string
}
export interface RetrieveItemType {
    categoryId: string
    categoryName: string
    id: string
    name: string
    pic: string
    salePrice: string
    salesVolume: string
    shopName: string
    shopId: string
}
/**
 * 商品检索
 */
export const doGetRetrieveCommodity = (data: Partial<RetrieveParam>) => {
    return api.post('gruul-mall-search/search/product', data)
}
/**
 * 获取非页面装修数据
 */
export const doGetNotPageInfo = (platform: string, functionType: keyof typeof FUNCTIONTYPE) => {
    return api.get(`gruul-mall-shop/decoration/not/page/info?aggregationPlatform=${platform}&functionType=${functionType}`)
}
/**
 * 装修分类页查询分类
 * @param {string} ids
 * @param {string} categoryLevel
 */
export const doGetCategoryLevel = (ids: string[], categoryLevel: string) => {
    return api.get('/gruul-mall-goods/goods/product/category/by/ids', { ids: ids.join(','), categoryLevel })
}
/**
 * 根据二级分类id查询商品
 */
export const doGetCommodityBySecCateId = (ids: string, categoryLevel: string) => {
    return api.get('/gruul-mall-goods/api/product/by/categoryId', {
        ids,
        categoryLevel,
    })
}
/**
 * 获取聚合首页名称
 */
export const doGetEnumOfDecoration = (list: string[]) => {
    return api.get(`gruul-mall-shop/decoration/aggregation/decorate?aggregationPlatforms=${list.join(',')}`)
}
